package com.platform.controller;

import com.platform.entity.GiftTypeEntity;
import com.platform.entity.GoodsAttributeEntity;
import com.platform.entity.GoodsEntity;
import com.platform.service.GiftTypeService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("giftType")
public class GiftTypeController {
    @Autowired
    private GiftTypeService giftTypeService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        //查询所有
        List<GiftTypeEntity> giftTypeEntities = giftTypeService.queryList();
        //查询总条数
        int total = giftTypeService.queryTotal();
        //分页
        PageUtils pageUtil = new PageUtils(giftTypeEntities, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public R save(@RequestBody GiftTypeEntity giftTypeEntity){
        giftTypeService.save(giftTypeEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public R update(@RequestBody GiftTypeEntity giftTypeEntity){
        giftTypeService.update(giftTypeEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public R delete(@RequestBody Integer[] ids){
        giftTypeService.deleteBatch(ids);
        return R.ok();
    }

    /**
     * 查看信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.GET)
    public R info(@PathVariable("id") Integer id) {
        GiftTypeEntity giftTypeEntity = giftTypeService.queryObject(id);
        return R.ok().put("giftTypeEntity", giftTypeEntity);
    }
}
